package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Brand 品牌
type Brand struct {
	ID         string `json:"id,omitempty" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	Name       string `json:"name,omitempty" gorm:"column:name;index:name_location,unique;type:string;size:40;comment:品牌名称"`
	Logo       string `json:"logo,omitempty" gorm:"column:logo;type:string;size:200;comment:品牌logo"`
	Desc       string `json:"desc,omitempty" gorm:"column:desc;type:text;comment:品牌描述"`
	LocationID string `json:"location_id" gorm:"column:location_id;index:name_location,unique;type:int;size:64;default:null;comment:位置id"`
	CreatedAt  int64  `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"updated_at,omitempty" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (Brand) TableName() string {
	return "brand"
}

// BeforeCreate 自增id
func (l *Brand) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Brand{})
}
